<?php

class spCheckboxList extends spDiv
{
	public function __construct( $param )
	{
		parent::__construct( $param );	
	}
	
	public function addItems( $items )
	{
		foreach ( $items as $i )
		{
			$this->addItem( $i );
		}
	}
	
	public function addItem( $item )
	{
		$p = parent::getData();
		$name = $p["name"];

		$label =  new spLabel(array(
			"contentAfter" => $item["content"]
		));
		
		$input = new spInputCheckbox( array(
			"name_id"	=> $item["value"],
			"name" 		=> $name."[]",
			"value"		=> $item["value"]
		));
		
		$label->addChild( $input );
		parent::addChild( $label );
		parent::addChild( new spBreak );
	}
	
	public function selectItems( $ar )
	{
		if ( !is_array($ar) )
			$ar = explode( ",", $ar );
	
		foreach ( $ar as $a )
		{
			$checkbox = parent::find( $a );
			if ( $checkbox )
				$checkbox->addAttr( "checked", "checked" );	
		}
	}
	
	public function setElementDataString( $s )
	{
		$ar = explode( ",", $s );
		$this->selectItems( $ar );
		
	}
}

?>